/*
 * @Description: 
 * @Author: xuzp4
 * @Date: 2021-10-29 17:01:42
 * @LastEditors: xuzp4
 * @LastEditTime: 2022-01-19 14:21:28
 * @FilePath: \vue_demo\src\service\index.js
 */
import AWS from 'aws-sdk'
import uploads from '@mapbox/mapbox-sdk/services/uploads'
export const uploadsClient = uploads({
  accessToken:
    "sk.eyJ1IjoieHUwNDMwIiwiYSI6ImNreWpzanpvcjB3NjIybnFvdjQ3eGoxZ24ifQ.fv-c0afyBoOEB19zgdGclQ"
});

export const getCredentials = () => {
  return uploadsClient
    .createUploadCredentials()
    .send()
    .then(response => {
      return response.body;
    });
};
export const putFileOnS3 = (credentials, file) => {
  const s3 = new AWS.S3({
    accessKeyId: credentials.accessKeyId,
    secretAccessKey: credentials.secretAccessKey,
    sessionToken: credentials.sessionToken,
    region: "us-east-1"
  });
  return s3
    .putObject({
      Bucket: credentials.bucket,
      Key: credentials.key,
      Body: file
    })
    .promise();
};